# Makefile for MarkLocalize

.PHONY: help install test lint format build clean dev-install run

# Default target
help:
	@echo "Available targets:"
	@echo "  install     - Install dependencies"
	@echo "  dev-install - Install development dependencies"
	@echo "  test        - Run tests"
	@echo "  lint        - Run linting"
	@echo "  format      - Format code"
	@echo "  build       - Build executable"
	@echo "  clean       - Clean build artifacts"
	@echo "  run         - Run the application"

# Install production dependencies
install:
	pip install -r requirements.txt

# Install development dependencies
dev-install: install
	pip install pytest pytest-qt pytest-cov flake8 black mypy pyinstaller

# Run tests
test:
	python -m pytest tests/ -v

# Run tests with coverage
test-cov:
	python -m pytest tests/ -v --cov=. --cov-report=html --cov-report=term-missing

# Run linting
lint:
	flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
	flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics

# Format code
format:
	black .

# Check formatting
format-check:
	black --check --diff .

# Type checking
type-check:
	mypy MarkLocalize.py --ignore-missing-imports

# Build executable
build: clean
	pyinstaller build.spec

# Build with UPX compression
build-compressed: clean
	pyinstaller --upx-dir=upx build.spec

# Clean build artifacts
clean:
	rm -rf build/
	rm -rf dist/
	rm -rf __pycache__/
	rm -rf *.egg-info/
	rm -rf .pytest_cache/
	rm -rf .coverage
	rm -rf htmlcov/
	rm -rf .mypy_cache/

# Run the application
run:
	python MarkLocalize.py

# Create release package
package: build
	mkdir -p release
	cp dist/MarkLocalize.exe release/
	cp README.md release/
	cp LICENSE release/
	cp CHANGELOG.md release/
	cp config.json release/
	cp examples/sample.md release/

# Development setup
dev-setup: dev-install
	@echo "Development environment setup complete"
	@echo "Run 'make test' to run tests"
	@echo "Run 'make run' to start the application"

# Quick development cycle
dev: format lint test
	@echo "Development checks passed"

# Pre-commit checks
pre-commit: format-check lint type-check test
	@echo "Pre-commit checks passed"

# Release preparation
release-prep: clean format lint type-check test build package
	@echo "Release preparation complete"
	@echo "Check the 'release' directory for packaged files"